package com.spzx.cart.controller;


import com.spzx.cart.api.domain.CartInfo;
import com.spzx.cart.service.ICartService;
import com.spzx.common.core.constant.SecurityConstants;
import com.spzx.common.core.domain.R;
import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "购物车接口")
@RestController
@RequestMapping
public class CartController extends BaseController {

    @Autowired
    ICartService cartService;

    @PutMapping("/updateCartPrice")
    R<Boolean> updateCartPrice(){
        int i = cartService.updateCartPrice();
        return R.ok();
    }

    @DeleteMapping("/removeCheckedCart")
    R<Boolean> removeCheckedCart(){
        int i = cartService.removeCheckedCart();
        return R.ok();
    }

    @GetMapping("/checkCart/{skuId}/{status}")
    public AjaxResult checkCart(@PathVariable Long skuId,@PathVariable Integer status){
        cartService.checkCart(skuId,status);
        return AjaxResult.success();
    }

    @DeleteMapping("/deleteCart/{skuId}")
    public AjaxResult deleteCart(@PathVariable Long skuId){
        cartService.deleteCart(skuId);
        return AjaxResult.success();
    }

    @GetMapping("addToCart/{skuId}/{skuNum}")
    public AjaxResult addToCart(@PathVariable Long skuId, @PathVariable Integer skuNum){
        cartService.addToCart(skuId,skuNum);
        return success();
    }

    @GetMapping("cartList")
    public AjaxResult cartList(){
        List<CartInfo> cartInfoList = cartService.cartList();
        return success(cartInfoList);
    }

}
